package web.fabrimind.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.pm.domain.ProductionPlan;
import web.fabrimind.wms.domain.WarehouseLocation;
import web.fabrimind.wms.service.IWarehouseLocationService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 仓库库位Controller
 * 
 * @author zhihui
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/wms/location")
public class WarehouseLocationController extends BaseController
{
    @Autowired
    private IWarehouseLocationService warehouseLocationService;

    /**
     * 查询仓库库位列表
     */
    @PreAuthorize("@ss.hasPermi('wms:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseLocation warehouseLocation)
    {
        startPage();
        List<WarehouseLocation> list = warehouseLocationService.selectWarehouseLocationList(warehouseLocation);
        return getDataTable(list);
    }

    /**
     * 导出仓库库位列表
     */
    @PreAuthorize("@ss.hasPermi('wms:location:export')")
    @Log(title = "仓库库位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseLocation warehouseLocation)
    {
        List<WarehouseLocation> list = warehouseLocationService.selectWarehouseLocationList(warehouseLocation);
        ExcelUtil<WarehouseLocation> util = new ExcelUtil<WarehouseLocation>(WarehouseLocation.class);
        util.exportExcel(response, list, "仓库库位数据");
    }

    /**
     * 获取仓库库位详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:location:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Long locationId)
    {
        return success(warehouseLocationService.selectWarehouseLocationByLocationId(locationId));
    }

    /**
     * 新增仓库库位
     */
    @PreAuthorize("@ss.hasPermi('wms:location:add')")
    @Log(title = "仓库库位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseLocation warehouseLocation)
    {
        return toAjax(warehouseLocationService.insertWarehouseLocation(warehouseLocation));
    }

    /**
     * 修改仓库库位
     */
    @PreAuthorize("@ss.hasPermi('wms:location:edit')")
    @Log(title = "仓库库位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseLocation warehouseLocation)
    {
        return toAjax(warehouseLocationService.updateWarehouseLocation(warehouseLocation));
    }

    /**
     * 删除仓库库位
     */
    @PreAuthorize("@ss.hasPermi('wms:location:remove')")
    @Log(title = "仓库库位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Long[] locationIds)
    {
        return toAjax(warehouseLocationService.deleteWarehouseLocationByLocationIds(locationIds));
    }


    /**
     * 查询所属仓库列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('wms:warehouse:list')")
    @GetMapping("/warehouse/getlist")
    public AjaxResult getWarehouseList(WarehouseLocation warehouseLocation) {
        List<WarehouseLocation> warehouseList = warehouseLocationService.selectWarehouseList(warehouseLocation);
        return AjaxResult.success(warehouseList);
    }



}
